﻿using Assets.XyzCode.Fight.UI;

using UnityEngine;

namespace Assets.XyzCode.Fight.Game.Enemy
{
    partial class Enemy_X_Behav
    {
        /// <summary>
        /// 减血
        /// </summary>
        /// <param name="subtractHP">减血量</param>
        /// <returns>this 指针</returns>
        public Enemy_X_Behav SubtractHP(int subtractHP)
        {
            if (0 == subtractHP)
            {
                return this;
            }

            Color usingColor = Color.white;

            if (subtractHP >= 10)
            {
                usingColor = Color.yellow;
            }

            GameObject goSubtractHPText = FloatTextFactory.Create(subtractHP.ToString(), usingColor);
            Vector3 atPos = transform.position;
            atPos = atPos + Vector3.up * (3 + Random.Range(-0.48f, +0.48f));
            atPos = atPos + Vector3.right * Random.Range(-0.64f, +0.64f);
            goSubtractHPText.transform.position = Camera.main.WorldToScreenPoint(atPos);

            return this;
        }
    }
}
